﻿Public Class TaskverwaltungAdapter
    Inherits StammdatenverwaltungAdapter(Of frmTaskverwaltung, TaskverwaltungListener, Task)

    Sub New()
        MyBase.New(New frmTaskverwaltung())
        setComboboxes(form.cbxKunde, form.cbxProjekte, Nothing)

        setListView(form.lsvTasks)
        addColumn("Titel", "titel")

        setDeleteButton(form.btnDelete)
        setSaveButton(form.btnSave)
        setEditButton(form.btnBearbeiten)

        Context.KUNDE_PROJEKT_TASK_SERVICE.getObservable().addListener(Me)
    End Sub

    'kpt actions:
    Public Overrides Sub onSelectedProjektChanged(ByRef projekt As Projekt)
        MyBase.onSelectedProjektChanged(projekt)
        setData(projekt.tasks)
    End Sub

    Protected Overrides Function getFormEntity(ByRef editEntity As Task) As Task
        Dim entity As New Task()
        If editEntity IsNot Nothing Then
            entity = editEntity
        End If
        entity.projekt = Me.getSelectedProjekt()
        entity.titel = form.txtTaskTitel.Text
        Return entity
    End Function

    Protected Overrides Sub setFormEntity(ByRef entity As Task)
        form.txtTaskTitel.Text = entity.titel
    End Sub

    Protected Overrides Sub clearForm()
        Me.form.txtTaskTitel.Text = ""
    End Sub

End Class
